<?php
/**
 * True Gallery Vote Stars template file
 *
 * @version 2.5
 * @author Alexey N. Brin (userxp@joomlaportal.ru)
 * @homepage http://truegallery.ru 
 * @filename votestars.tpl.php
 * @package True Gallery
 * @copyright (C) 2008-2009 by joomlatune.ru
 * @license GNU/GPL: http://www.gnu.org/copyleft/gpl.html
 * 
 * THIS GALLERY is an EVOLUTION of AkoGallery -> PonyGallery -> DatsoGallery
 *
 * If you fork this to create your own project, 
 * please make a reference to True Gallery someplace in your code 
 * and provide a link to http://www.joomlatune.ru
 *
 **/

defined('_VALID_MOS') or defined('_JEXEC') or die('Direct Access to this location is not allowed.');

?><div style="margin: 5px 15px;"><?php

if( $tpl->imgvotes > 0 ) {
	$votes_text = "(" . JText::_('TGVOTE_VOTES') . $tpl->imgvotes . ")";
} else {
	$votes_text = "(" . JText::_('TGVOTE_NO_VOTES') . ")";
}

$ad_showrating = JTuneConfig::getValue('ad_showrating');

if( $ad_showrating ) { ?>
	<script type="text/javascript">
	function getVote(rating) {
		var id = <?php echo $tpl->id; ?>;
		var div = jQuery("#tgvote"+id);
		
		<?php if( $row->owner==$my->id ) { ?>
		div.html('<?php echo JText::_('TG_OWNER_NO_VOTE'); ?>');
		setTimeout( function() {
			div.html('<?php echo $votes_text; ?>');
		}, 1000);
		return;
		<?php } ?>
		
		div.html('<img src="<?php echo JTuneLayout::getImageFile('loading', '.gif'); ?>" border="0" align="absmiddle" /> '+'<?php echo JText::_('TGVOTE_UPDATING'); ?>');
		var url = 'index2.php?option=<?php echo TG_CMP; ?>';
		jQuery.get( url, {
				view		: 'pictures',
				task		: 'recordvote',
				ax			: '1',
				no_html		: '1',
				user_rating	: rating,
				id			: id
			}, 
			function( responseData, textStatus ) {
				var total = <?php echo $tpl->imgvotesum; ?>;
				var total_count = <?php echo $tpl->imgvotes; ?>;
				
				setTimeout( function() {
					if( responseData=='1' ) {
						div.html('<?php echo JText::_('TGVOTE_THANKS'); ?>');
					}
					else {
						div.html('<?php echo JText::_('TGVOTE_ALREADY_VOTE'); ?>');
					}
				}, 1000);
				
				setTimeout( function() {
					if( responseData=='1' ) {
						div.html('(<?php echo JText::_('TGVOTE_VOTES').' '.($tpl->imgvotes+1); ?>)');
						var percentage = ((total + rating)/(total_count+1))*20;
						document.getElementById('rating'+id).style.width = percentage+'%';
					} else {
						div.html('(<?php echo JText::_('TGVOTE_VOTES').' '.$tpl->imgvotes; ?>)');
					}
				}, 3000);
			}
		);
	}
	</script>
	<?php 
	$my = &getUser();
	
	//if( $row->owner != $my->id) { ?>
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
		<tr>
			<td>
				<div class="tgvote-inline">
					<ul class="tgvote-star">
						<li id="rating<?php echo $tpl->id; ?>" class="current" style="width:<?php echo $tpl->imgpoints * 20; ?>%"></li>
						<li><a href="javascript:void(0)" onclick="javascript:getVote(1);" title="1 <?php echo JText::_('TGVOTE_STAR1'); ?> 5" class="one-star">1</a></li>
						<li><a href="javascript:void(0)" onclick="javascript:getVote(2);" title="2 <?php echo JText::_('TGVOTE_STAR234'); ?> 5" class="two-stars">2</a></li>
						<li><a href="javascript:void(0)" onclick="javascript:getVote(3);" title="3 <?php echo JText::_('TGVOTE_STAR234'); ?> 5" class="three-stars">3</a></li>
						<li><a href="javascript:void(0)" onclick="javascript:getVote(4);" title="4 <?php echo JText::_('TGVOTE_STAR234'); ?> 5" class="four-stars">4</a></li>
						<li><a href="javascript:void(0)" onclick="javascript:getVote(5);" title="5 <?php echo JText::_('TGVOTE_STAR5'); ?> 5" class="five-stars">5</a></li>
					</ul>
				</div>
			</td>
			<td width="100%">
				<div id="tgvote<?php echo $tpl->id; ?>">&nbsp;&nbsp;<?php echo $votes_text; ?></div>
			</td>
		</tr>
	</table><?php 
	//}
}
?></div>